import math


class Solution(object):
    def isPowerOfThree(self, n):
        """
        :type n: int
        :rtype: bool
        """
        if n <= 0:
            return False
        a = round(math.log(n, 3))
        return 3 ** a == n


data = Solution()
n = 9
print(data.isPowerOfThree(n))
